package com.hunlian.makelove.net.api;

import android.content.Context;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.hunlian.makelove.bean.Banner;
import com.hunlian.makelove.net.ServiceInterfaceDef;
import com.hunlian.makelove.net.InterfaceServiceVisit;
import com.hunlian.makelove.net.ResponseCallbackListener;
import com.hunlian.makelove.net.StringResponseCallbackListener;

import java.lang.reflect.Type;


/**
 * Banner
 * @author zealjiang
 * @time 2016年7月12日上午11:08:24
 */
public class BannerServiceVisit extends InterfaceServiceVisit {
	// banner接口Id


	public BannerServiceVisit(Context context) {
		super(context);

		setFunctionId(ServiceInterfaceDef.FUNC_ID_BANNER);
	}

	// 填充参数
	public void setParamters(String userId) {
		paramterData.put("userId", userId);
	}

	public void getResult(final ResponseCallbackListener<Banner,Object> listener) {
		doPost(getParamter(), new StringResponseCallbackListener() {
			@Override
			public void onSuccess(String data) {
				//Printout.println("banner反馈 :"+data);
			
				Type type = new TypeToken<Banner>(){}.getType();
				Gson gson = new Gson();
				Banner banner = gson.fromJson(data, type);
		        
				if(listener != null){
					listener.onSuccess(banner);
				}
			}

			@Override
			public void onFailure(String errCode, String errMessage,String obj) {
				if (listener != null) {
					listener.onFailure(errCode, errMessage,obj);
				}
			}
		});
	}


}
